home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
How to Get Online 1996 Spring
/
HOW2GON.ISO
/
mac
/
E-Mail
/
MacBiff ƒ
/
rbiff.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-01-22
|
4KB
|
185 lines
/*
"rbiff" program, by Jay Kreibich and SigSoft of ACM@UIUC.
For use with the programs MacBiff, and (maybe some year)
WinBiff.
(C) 1994 the Student Chapter of the Association for Computing Machinery
at the University of Illinois, Urbana - Champaign and SigSoft
(the Special Interest Group for Software Development), the UIUC
Department of Computer Science, UIUC, and most likely a bunch
of other people I don't know.
ACM at UIUC RESERVES ALL DISTRIBUTION RIGHTS.
Developed on SPARCstation IPX running SunOS 4.1.2. See MacBiff README
file for more info.
*/
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <pwd.h>
#define VERSION 3
typedef struct aPacket
{
unsigned char flag;
unsigned char version;
unsigned char userlen;
unsigned char tolen;
unsigned char fromlen;
unsigned char sublen;
char data[250];
} udpPacket;
char* GetNextLine(buffer, size, theFile)
char *buffer;
int size;
FILE *theFile;
{
if(fgets(buffer, size, theFile) == NULL)
return(NULL);
if(buffer[0] != '#')
{
buffer[strlen(buffer) - 1] = '\0';
return(buffer);
}
return GetNextLine(buffer, size, theFile);
}
int main(argc, argv)
int argc;
char **argv;
{
udpPacket msg;
struct sockaddr_in name;
struct hostent *hp;
struct passwd *pw;
char buff[256], subj[256],
from[256], host[256],
*beg, *end;
FILE *config;
long soc,
index = 0;
short nogood,
looksub = 1,
lookfrm = 1,
port = 0;
bzero(&msg, sizeof(msg));
msg.flag = 42;
msg.version = VERSION;
pw = getpwnam(cuserid(NULL));
while(fgets(buff, 256, stdin) != NULL)
{
if(lookfrm)
{
if(strncmp("From: ", buff, 6) == 0)
{
strncpy(from, &buff[6], 50);
lookfrm = 0;
if(((beg = strchr(buff, '(')) != NULL)
&&((end = strchr(buff, ')')) != NULL))
{
*end = 0;
strncpy(from, beg+1, 50);
}
else
{
if((beg = strchr(from, '<')) != NULL)
*beg = 0;
else
from[strlen(from)-1] = 0;
}
lookfrm = 0;
}
}
if(looksub)
{
if(strncmp("Subject: ", buff, 9) == 0)
{
strncpy(subj, &buff[9], 50);
subj[strlen(subj)-1] = 0;
looksub = 0;
}
}
}
strcpy(buff, pw->pw_dir);
strcat(buff, "/.rbiffrc");
if((config = fopen(buff, "r")) == NULL)
{
fprintf(stderr, "%s: Could not open .rbiffrc file\n", argv[0]);
exit(2);
}
if(GetNextLine(buff, 256, config) == NULL)
{
fprintf(stderr, "%s: No personal name found in .rbiffrc file\n", argv[0]);
exit(2);
}
msg.userlen = strlen(buff);
memccpy(&msg.data[index], buff, '\0', 50);
index += msg.userlen + 1;
if(GetNextLine(buff, 256, config) == NULL)
{
fprintf(stderr, "%s: No account name found in .rbiffrc file\n", argv[0]);
exit(2);
}
msg.tolen = strlen(buff);
memccpy(&msg.data[index], buff, '\0', 50);
index += msg.tolen + 1;
msg.fromlen = strlen(from);
memccpy(&msg.data[index], from, '\0', 50);
index += msg.fromlen + 1;
msg.sublen = strlen(subj);
memccpy(&msg.data[index], subj, '\0', 50);
index += msg.sublen + 1;
index += 6;
soc = socket(AF_INET, SOCK_DGRAM,0);
name.sin_family = AF_INET;
while(GetNextLine(buff, 256, config) != NULL)
{
nogood = sscanf(buff, "%s %hd", host, &port);
if(nogood > 1)
name.sin_port = htons(port);
else
name.sin_port = htons(4545);
hp = gethostbyname(host);
memcpy(&name.sin_addr.s_addr, hp->h_addr_list[0], hp->h_length);
connect(soc, &name, sizeof(name));
write(soc, &msg, index);
}
fclose(config);
return 0;
}